package com.ntes.provider2.controller;

import com.ntes.model.User;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by bjliuyue1 on 2017/5/19.
 */
@RestController
public class DemoController2 {

    @Value("${server.port}")
    int port;

    @RequestMapping("/getString")
    public String getString(HttpServletRequest request) {
        String str = "provider2 at port " + port + ":" + request.getParameter("name") + " " + new Date();
        return str;
    }

    @RequestMapping("/getUser")
    public User getUser(HttpServletRequest request) {
        User user = new User();
        user.setAge(180);
        user.setName(request.getParameter("name"));
        user.setPort(port);
        return user;
    }

    @RequestMapping("/getUserString")
    public String getUserString(HttpServletRequest request) {
        User user = new User();
        user.setAge(190);
        user.setName(request.getParameter("name"));
        user.setPort(port);
        return user.toString();
    }
}
